package query.python;


import cn.edu.buaa.neo.codegraphql.core.graph.values.statements.expressions.CallExpression;
import cn.edu.buaa.neo.codegraphql.dsl.fluent.query.QueryDescriptor;
import cn.edu.buaa.neo.codegraphql.dsl.lib.engine.QueryEngine;
import cn.edu.buaa.neo.codegraphql.language.python.PythonQuery;
import cn.edu.buaa.neo.codegraphql.language.python.lib.predicate.ContainsFunctionCall;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.PrintStream;

public class FluentQueryTest {
    @Test
    public void fluentQueryTest() {
        QueryEngine.getInstance()
                .execute("FluentQueryTest", new FluentQuery())
                .close();
        Assertions.assertTrue(true);
    }

    private static class FluentQuery extends PythonQuery {
        @Override
        public void run(String style, PrintStream output) {
            QueryDescriptor.open()
                    .from("call", CallExpression.class)
                    .where(q -> q.onTable("call")
                            .where(new ContainsFunctionCall("app.run").onColumn("call")))
                    .select("call", "Flask app run found!")
                    .display();
        }
    }
}
